package com.duobaoyu.dby.supply.job.task.supply;

import com.alibaba.fastjson2.JSON;
import com.duobaoyu.dby.supply.biz.client.boundary.order.bean.dto.OrderTaskDTO;
import com.duobaoyu.dby.supply.job.service.order.OrderJobService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author fengshaoyu
 * @version 1.0.0
 * @date 2023/10/21 9:47
 */
@Component
@RequiredArgsConstructor
public class SupplyChainOrderTask {
	private final OrderJobService orderJobService;

	/**
	 * 每日定时同步三方状态
	 */
	@XxlJob("syncOrderStatusJob")
	public void syncOrderStatusJobHandler(){
		String orderStatusJobJson = XxlJobHelper.getJobParam();
		OrderTaskDTO orderTask = OrderTaskDTO.builder().build();
		if(Objects.nonNull(orderStatusJobJson)){
			orderTask = JSON.parseObject(orderStatusJobJson, OrderTaskDTO.class);
		}
		orderJobService.listSyncOrderStatusData(orderTask);
	}

	@XxlJob("autoOrderConfirmCompleteJob")
	public void autoOrderConfirmCompleteJobHandler() {
		orderJobService.autoOrderConfirmComplete();
	}
}
